<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

      <el-form-item>
        <el-date-picker
          :editable="false"
          type="month"
          v-model="dataForm.date"
          value-format="yyyy-MM"
          format="yyyy-MM"
          style="width:150px;"
          placeholder="选择月份">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-input v-model="name" placeholder="驾驶员姓名" clearable @input="inputName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">


      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="salary"
        header-align="center"
        align="center"
        label="工资(元)">
      </el-table-column>
      <el-table-column
        prop="takeAmount"
        header-align="center"
        align="center"
        label="已发放(元)">
      </el-table-column>
      <el-table-column
        prop="balance"
        header-align="center"
        align="center"
        label="未发放(元)">
      </el-table-column>
      <!--      <el-table-column-->
      <!--        width="200px"-->
      <!--        prop="createTime"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        label="工资账期">-->
      <!--      </el-table-column>-->
      <el-table-column
        prop="days"
        header-align="center"
        align="center"
        label="出车天数">
      </el-table-column>
      <el-table-column
        prop="receiveWeight"
        header-align="center"
        align="center"
        label="运输吨数">
      </el-table-column>
      <el-table-column
        prop="shipmentCount"
        header-align="center"
        align="center"
        label="运输次数">
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        label="手机号">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('tms:salary:pay')  && scope.row.balance >0" type="text" size="small"
                     @click="payHandler(scope.row.driverId)">
            发放工资
          </el-button>
          <el-button type="text" size="small" @click="detailHandler(scope.row.driverId)">明细</el-button>

        </template>
      </el-table-column>
    </el-table>
    <!--    <el-pagination-->
    <!--      @size-change="sizeChangeHandle"-->
    <!--      @current-change="currentChangeHandle"-->
    <!--      :current-page="pageIndex"-->
    <!--      :page-sizes="[10, 20, 50, 100]"-->
    <!--      :page-size="pageSize"-->
    <!--      :total="totalPage"-->
    <!--      layout="total, sizes, prev, pager, next, jumper">-->
    <!--    </el-pagination>-->
    <pay v-if="pay" ref="pay" @refreshDataList="getDataList"></pay>
    <detail v-if="detailBool" ref="detail" @refreshDataList="getDataList"></detail>
  </div>
</template>

<script>
import Utils from '@/utils/utils'
import pay from './pay'
import detail from './detail'

export default {
  components: {
    pay, detail
  },
  data () {
    return {
      name: '',
      dataForm: {
        date: ''
      },
      dataList: [],
      cloneList:[],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      pay: false,
      detailBool: false
    }
  },
  activated () {
    this.dataForm.date = Utils.getCurrentMonth()
    this.getDataList()
  },
  computed: {
    // filteredList() {
    //   return this.dataList.filter(item => {
    //     return item.name.toLowerCase().includes(this.name.toLowerCase());
    //   });
    // }
  },
  methods: {
    inputName () {
      console.log(this.name)
      let list = []
      list = this.dataList.filter(item => {
        return item.name.toLowerCase().indexOf(this.name.toLowerCase()) !== -1
        // return item.name.toLowerCase().includes(this.name.toLowerCase());
      })
      this.dataList = list
      if (this.name === '') {
        this.dataList = this.cloneList
      }
     // console.log(this.dataList)
    },
    detailHandler (id) {
      this.detailBool = true
      this.$nextTick(() => {
        this.$refs.detail.init(id, this.dataForm.date)
      })
    },
    payHandler (id) {
      this.pay = true
      this.$nextTick(() => {
        this.$refs.pay.init(id, this.dataForm.date)
      })
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/statistic/salary'),
        method: 'get',
        params: this.$http.adornParams({
          'date': this.dataForm.date
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.list
          this.cloneList = this.dataList
         // this.cloneList = JSON.parse(JSON.stringify(this.dataList ))
          //this.totalPage = data.page.totalCount
        } else {
          // this.dataList = []
          // this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    }
  }
}
</script>
